<template>
  <div class="big-box">
    <!-- <img class="bagimg" src="./../../static/img/fmt.png"> -->
    <!-- <div class="submit-form-box">
      <div @click="openPage()" class="submit-form">
        立即报名
      </div>
    </div>-->
  </div>
</template>
<script>
export default {
  data() {
    return {
      locationSearch: "" //URL
    };
  },
  created() {
    this.locationSearch = location.href;

    if (this.GetUrlParam("channelId")) {
      this.$store.state.urlParam.channelId = this.initUrl("channelId");
    } else {
      this.$store.state.urlParam.channelId = "7";
    }
    if (this.GetUrlParam("corpId")) {
      this.$store.state.urlParam.corpId = this.initUrl("corpId");
    } else {
      this.$store.state.urlParam.corpId =
        "ding6b9a7f1ffe5abccf35c2f4657eb6378f";
    }

    console.log(this.$store.state.urlParam.channelId);
    console.log(this.$store.state.urlParam.corpId);

    if (
      this.GetUrlParam("activeId") != "activeId" ||
      this.GetUrlParam("ticketTypeId") != "ticketTypeId"
    ) {
      this.$Toast({
        message: "参数传递错误",
        position: "middle",
        duration: 3000
      });
      return;
    } else {
      // return;
      this.$store.state.urlParam.activityId = this.initUrl("activeId");
      this.$store.state.urlParam.ticketTypeId = this.initUrl("ticketTypeId");
      this.getFormFiled();
    }
    sessionStorage.setItem(
      "urlParam",
      JSON.stringify(this.$store.state.urlParam)
    );
    if (!this.$store.state.formFiled.componenList.length) {
      setTimeout(() => {
        this.$router.push({
          name: "form"
        });
      }, 300);
    }
  },
  methods: {
    initUrl(name) {
      return (
        decodeURIComponent(
          (new RegExp("[?|&]" + name + "=" + "([^&;]+?)(&|#|;|$)").exec(
            this.locationSearch
          ) || [, ""])[1].replace(/\+/g, "%20")
        ) ||
        JSON.parse(sessionStorage.getItem("urlParam"))[name] ||
        ""
      );
    },
    GetUrlParam(paraName) {
      var url = this.locationSearch;
      var arrObj = url.split("?");

      if (arrObj.length > 1) {
        var arrPara = arrObj[1].split("&");
        var arr;

        for (var i = 0; i < arrPara.length; i++) {
          arr = arrPara[i].split("=");
          if (arr != null && arr[0] == paraName) {
            return arr[0];
          }
        }
        return "";
      } else {
        return "";
      }
    },
    // 得到表单字段
    getFormFiled() {
      this.$Indicator.open({
        text: "获取数据中",
        spinnerType: "fading-circle"
      });
      let subData = {
        activityId: this.$store.state.urlParam.activityId,
        ticketTypeId: this.$store.state.urlParam.ticketTypeId,
        isPay: "free"
      };
      this.$http.post("/api/isv/temp/queryTempletByTicketTypeId", subData).then(
        res => {
          this.$Indicator.close();
          if (res.data.code == 100) {
            // 确定表单字段
            this.$store.state.formFiled.componenList = [];
            this.$store.state.formFiled.componenList = JSON.parse(
              res.data.data.vnote1
            );
            sessionStorage.setItem("componenList", res.data.data.vnote1);
            this.$store.state.urlParam.tempId = res.data.data.id;
            // 添加论坛选择组件
            let forum = {
              componentName: "selForumTem",
              attribute: {
                filedValue: "3" - 0,
                filedValuebbsname: "test", //新增加为了显示名称
                filedCode: "bbsId",
                titName: "分论坛意向",
                placeholder: "请选择",
                ifCheck: true,
                selectList: []
              }
            };
            this.$store.state.formFiled.componenList.push(forum); // 添加论坛选择组件
            // 默认添加一个参会人
            let obj = JSON.parse(JSON.stringify(this.$store.state.formFiled));
            obj.templateId = Number(new Date());
            this.$store.state.formList = [];
            this.$store.state.formList.push(obj); //添加表格数据
            // console.log(this.$store.state.formList);
          } else {
            let errMsg = res.data.errMsg;
            if (errMsg.length > 100) {
              errMsg = "";
            }
            this.$Toast({
              message: errMsg || "表单字段数据获取失败",
              position: "middle",
              duration: 3000
            });
          }
        },
        err => {
          this.$Indicator.close();
          this.$Toast({
            message: "数据获取失败",
            position: "middle",
            duration: 3000
          });
        }
      );
    },
    openPage() {
      this.$router.push({
        name: "form"
      });
    }
  }
};
</script>
<style scoped >
.big-box {
  width: 100%;
  height: 100%;
  background: #f4f5f4;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.bagimg {
  width: 100%;
  height: auto;
  float: left;
}
.submit-form-box {
  position: fixed;
  bottom: 8%;
  left: 50%;
  width: 100%;
  transform: translateX(-50%);
  height: 5rem;
  z-index: 99;
  background: #ffffff;
  /* border-top: 0.1rem solid #dedede; */
  display: flex;
  -webkit-display: flex;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-align-items: center;
  align-items: center;
}
.submit-form {
  background: #ff3e85;
  font-size: 1.4rem;
  color: #ffffff;
  width: 69%;
  height: 3.5rem;
  line-height: 3.5rem;
  cursor: pointer;
}
.submit-form:active {
  background: rgba(249, 29, 112, 0.6);
}
</style>

